// app.js
App({
  onLaunch: function () {
    const systemInfo = wx.getSystemInfoSync();
    const menuButtonInfo = wx.getMenuButtonBoundingClientRect();
    
    // 初始化全局数据
    this.globalData = {
      isLogin: false,
      token: null,
      programme: {},
      selectedProducts: [],
      isUploading:true,
      importHouse: null,
      serviceType:null,
      roomList: [],
      selectedAddress: {},
      selectedHouseType: {},
      serviceProviderStatus: 0,
      navBarHeight: systemInfo.statusBarHeight + 44,
      menuRight: systemInfo.screenWidth - menuButtonInfo.right,
      menuBotton: menuButtonInfo.top - systemInfo.statusBarHeight,
      menuHeight: menuButtonInfo.height,
      someData: { type: null, val: null },
    };
  },

  // 更新全局登录状态的函数
  updateLoginStatus: function (isLogin, token = null) {
    this.globalData.isLogin = isLogin;
    this.globalData.token = token;
    
    if (isLogin) {
      wx.setStorageSync('token', token);
    } else {
      wx.clearStorageSync();
    }
    
    this.refreshTabBarPages(); // 更新登录状态后刷新 tabbar 页面
  },

  // 刷新所有 tabbar 页面
  refreshTabBarPages: function () {
    const pages = [
      '/pages/quick/index',
      '/pages/message/index',
      '/pages/home/index'
    ];
    
    pages.forEach(url => {
      wx.switchTab({
        url: url,
        success: () => {
          const page = getCurrentPages().pop(); // 获取当前页面实例
          if (page) {
            page.onShow(); // 手动调用 onShow 方法刷新页面
          }
        }
      });
    });
  },

  // 获取全局登录状态
  getLoginStatus: function () {
    return {
      isLogin: this.globalData.isLogin,
      token: this.globalData.token,
    };
  },

  
});
